<?php

declare(strict_types=1);

namespace app\core;

/**
 * 文件管理
 */
class File
{
    /**
     * 打开文件流
     *
     * @param string $filename
     * @param string $mode
     * @return resource
     */
    public static function open(string $filename, string $mode = 'a+')
    {
        return fopen($filename, $mode);
    }
    /**
     * 读文件流内容
     *
     * @param resource $stream
     * @param string $filename
     * @return void
     */
    public static function read($stream,string $filename)
    {
        return fread($stream, fileSize($filename));
    }
    /**
     * 写入文件流
     *
     * @param resource $stream
     * @param string $contents
     * @return int|false
     */
    public static function write($stream, string $contents)
    {
        return fwrite($stream, $contents, strlen($contents));
    }
    /**
     * 关闭文件流
     *
     * @param resource $stream
     * @return boolean
     */
    public static function close($stream): bool
    {
        return fclose($stream);
    }
}
